<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveRecord::Dirty</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveRecord::Dirty</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/activerecord/lib/active_record/dirty_rb.html">
                vendor/rails/activerecord/lib/active_record/dirty.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Track unsaved attribute <a href="Dirty.html#M001623">changes</a>.
</p>
<p>
A newly instantiated object is unchanged:
</p>
<pre>
  person = Person.find_by_name('uncle bob')
  person.changed?       # =&gt; false
</pre>
<p>
Change the name:
</p>
<pre>
  person.name = 'Bob'
  person.changed?       # =&gt; true
  person.name_changed?  # =&gt; true
  person.name_was       # =&gt; 'uncle bob'
  person.name_change    # =&gt; ['uncle bob', 'Bob']
  person.name = 'Bill'
  person.name_change    # =&gt; ['uncle bob', 'Bill']
</pre>
<p>
Save the <a href="Dirty.html#M001623">changes</a>:
</p>
<pre>
  person.save
  person.changed?       # =&gt; false
  person.name_changed?  # =&gt; false
</pre>
<p>
Assigning the same value leaves the attribute unchanged:
</p>
<pre>
  person.name = 'Bill'
  person.name_changed?  # =&gt; false
  person.name_change    # =&gt; nil
</pre>
<p>
Which attributes have <a href="Dirty.html#M001621">changed?</a>
</p>
<pre>
  person.name = 'bob'
  person.changed        # =&gt; ['name']
  person.changes        # =&gt; { 'name' =&gt; ['Bill', 'bob'] }
</pre>
<p>
Before modifying an attribute in-place:
</p>
<pre>
  person.name_will_change!
  person.name &lt;&lt; 'by'
  person.name_change    # =&gt; ['uncle bob', 'uncle bobby']
</pre>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M001622">changed</a>&nbsp;&nbsp;
      <a href="#M001621">changed?</a>&nbsp;&nbsp;
      <a href="#M001623">changes</a>&nbsp;&nbsp;
      <a href="#M001620">included</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Module <a href="Dirty/ClassMethods.html" class="link">ActiveRecord::Dirty::ClassMethods</a><br />

    </div>

    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DIRTY_SUFFIXES</td>
          <td>=</td>
          <td class="context-item-value">['_changed?', '_change', '_will_change!', '_was']</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M001620" class="method-detail">
        <a name="M001620"></a>

        <div class="method-heading">
          <a href="#M001620" class="method-signature">
          <span class="method-name">included</span><span class="method-args">(base)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001620-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001620-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/dirty.rb, line 39</span>
39:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">included</span>(<span class="ruby-identifier">base</span>)
40:       <span class="ruby-identifier">base</span>.<span class="ruby-identifier">attribute_method_suffix</span> <span class="ruby-operator">*</span><span class="ruby-constant">DIRTY_SUFFIXES</span>
41:       <span class="ruby-identifier">base</span>.<span class="ruby-identifier">alias_method_chain</span> <span class="ruby-identifier">:write_attribute</span>, <span class="ruby-identifier">:dirty</span>
42:       <span class="ruby-identifier">base</span>.<span class="ruby-identifier">alias_method_chain</span> <span class="ruby-identifier">:save</span>,            <span class="ruby-identifier">:dirty</span>
43:       <span class="ruby-identifier">base</span>.<span class="ruby-identifier">alias_method_chain</span> <span class="ruby-identifier">:save!</span>,           <span class="ruby-identifier">:dirty</span>
44:       <span class="ruby-identifier">base</span>.<span class="ruby-identifier">alias_method_chain</span> <span class="ruby-identifier">:update</span>,          <span class="ruby-identifier">:dirty</span>
45:       <span class="ruby-identifier">base</span>.<span class="ruby-identifier">alias_method_chain</span> <span class="ruby-identifier">:reload</span>,          <span class="ruby-identifier">:dirty</span>
46: 
47:       <span class="ruby-identifier">base</span>.<span class="ruby-identifier">superclass_delegating_accessor</span> <span class="ruby-identifier">:partial_updates</span>
48:       <span class="ruby-identifier">base</span>.<span class="ruby-identifier">partial_updates</span> = <span class="ruby-keyword kw">true</span>
49: 
50:       <span class="ruby-identifier">base</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:extend</span>, <span class="ruby-constant">ClassMethods</span>)
51:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M001622" class="method-detail">
        <a name="M001622"></a>

        <div class="method-heading">
          <a href="#M001622" class="method-signature">
          <span class="method-name">changed</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
List of attributes with unsaved <a href="Dirty.html#M001623">changes</a>.
</p>
<pre>
  person.changed # =&gt; []
  person.name = 'bob'
  person.changed # =&gt; ['name']
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001622-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001622-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/dirty.rb, line 65</span>
65:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">changed</span>
66:       <span class="ruby-identifier">changed_attributes</span>.<span class="ruby-identifier">keys</span>
67:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001621" class="method-detail">
        <a name="M001621"></a>

        <div class="method-heading">
          <a href="#M001621" class="method-signature">
          <span class="method-name">changed?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Do any attributes have unsaved changes?
</p>
<pre>
  person.changed? # =&gt; false
  person.name = 'bob'
  person.changed? # =&gt; true
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001621-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001621-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/dirty.rb, line 57</span>
57:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">changed?</span>
58:       <span class="ruby-operator">!</span><span class="ruby-identifier">changed_attributes</span>.<span class="ruby-identifier">empty?</span>
59:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001623" class="method-detail">
        <a name="M001623"></a>

        <div class="method-heading">
          <a href="#M001623" class="method-signature">
          <span class="method-name">changes</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Map of <a href="Dirty.html#M001622">changed</a> attrs =&gt; [original
value, new value].
</p>
<pre>
  person.changes # =&gt; {}
  person.name = 'bob'
  person.changes # =&gt; { 'name' =&gt; ['bill', 'bob'] }
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001623-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001623-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/dirty.rb, line 73</span>
73:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">changes</span>
74:       <span class="ruby-identifier">changed</span>.<span class="ruby-identifier">inject</span>({}) { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span>, <span class="ruby-identifier">attr</span><span class="ruby-operator">|</span> <span class="ruby-identifier">h</span>[<span class="ruby-identifier">attr</span>] = <span class="ruby-identifier">attribute_change</span>(<span class="ruby-identifier">attr</span>); <span class="ruby-identifier">h</span> }
75:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>